package com.fh.fruit.service.order.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.fruit.entity.order.Order;
import com.fh.fruit.service.order.OrderManager;
import com.fh.util.DateUtil;
import com.fh.util.PageData;

@Service("orderService")
public class OrderService implements OrderManager {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	/**订单列表
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<Order> listOrders(Page page)throws Exception{
		return (List<Order>) dao.findForList("OrderMapper.orderlist", page);
	}

	/**寄回订单列表
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> returnOrder(Page page) throws Exception {
		return (List<Map<String, Object>>) dao.findForList("OrderMapper.returnOrderlistPage", page);
	}

	@Override
	public int updateROrderState(PageData pd) throws Exception {
		String state=(String)pd.get("state");
		if("00".equals(state)){
			pd.put("state", "01");
		} else if("01".equals(state)){
			pd.put("delivery_time", DateUtil.getTime());
			pd.put("state", "02");
		} else if("02".equals(state)){
			pd.put("closing_time", DateUtil.getTime());
			pd.put("state", "03");
		}
		return (int) dao.update("OrderMapper.updateROrderState", pd);
	}
	

}
